package com.example.yuejian21.nongfusanquan.yuejian21.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.activity.ActivitydetailActivity;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Activitybean;
import com.squareup.picasso.Picasso;

import java.util.List;

import com.example.yuejian21.nongfusanquan.yuejian21.R;

/**
 * Created by Nongfusanquan on 2017-10-10.
 */

public class ActivityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private LayoutInflater mLayoutInflater;


    public ActivityAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_activitylist, parent, false);
        return new ViewHolder(v);


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Activitybean entity = (Activitybean) mDataList.get(position);

        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.title.setText(entity.getA_name() + "");
        viewHolder.activity_info.setText(entity.getA_info());
        final String t_picture = "http://10.0.2.2/yuejian14/Public/Admin/activitypicture/" + entity.getA_picture();
        if (!t_picture.equals("")) {
            Picasso.with(mContex).load(t_picture).into(viewHolder.photo);
        }


        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("a_id",entity.getA_id());
                bundle.putString("a_name",entity.getA_name());
                bundle.putString("a_phone",entity.getA_phone());
                bundle.putString("a_info",entity.getA_info());
                bundle.putString("a_picture",entity.getA_picture());
                bundle.putString("a_address",entity.getA_address());
                bundle.putInt("a_number",entity.getA_number());
                Intent intent=new Intent(mContex,ActivitydetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView photo, photo1;
        TextView title, activity_info, title1, activity_info1;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.activity_name);
            activity_info = (TextView) itemView.findViewById(R.id.activity_info);
            photo = (ImageView) itemView.findViewById(R.id.activity_photo);
        }

    }

}
